<header class="cmd-header clear">
    <h1 class="cmd-title left">备份数据</h1>
    <button class="btn btn-blue left" id="backup-btn">备份</button>
</header>
<ul class="cmd-list" id="backup-list">{{range .Files}}
    <li>
        <span class="time">{{DateTime .ModTime "MM.DD HH:mm"}}</span>
        <span class="name">{{.Name}} <a class="link" href="/cmd/backup/file?file={{.Name}}">下载</a></span>
        <span class="size">{{FileSize .Size}}</span>
        <a class="del" href="#" rel="{{.Name}}">删除</a>
    </li>{{end}}
</ul>
<script>
    $(function () {
        $('#backup-btn').on("click", function () {
            $.ajax({
                type: "post",
                beforeSend: function () {
                    $('.cmd-list').prepend('<li class="backup-loading">备份中..</li>');
                    $('#backup-btn').hide();
                },
                success: function (json) {
                    if (json.res) {
                        $('.backup-loading').remove();
                        $('.cmd-list').prepend('<li class="backup-result">刚刚备份到 ' + json.file + '</li>');
                    } else {
                        alert(json.msg);
                    }
                    $('#backup-btn').show();
                }
            });
            return false;
        });
        $('.del').on("click", function () {
            var that = this;
            $.ajax({
                url: "/cmd/backup/?file=" + $(this).attr("rel"),
                type: "delete",
                success: function (json) {
                    if(json.res){
                        $(that).parent().remove();
                    }
                }
            });
            return false;
        })
    })
</script>